import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import svgr from 'vite-plugin-svgr';
import { resolve } from 'node:path';

const rootDir = resolve(__dirname, '../');

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [react(), svgr()],
  resolve: {
    alias: [
      { find: '@', replacement: resolve(__dirname, 'src') },
      { find: /^@lle\/d3-editor/, replacement: resolve(rootDir, 'packages/d3-editor/index.ts') },
      { find: /^@lle\/d3-preview/, replacement: resolve(rootDir, 'packages/d3-preview/index.ts') },
    ],
  },
  css: {
    modules: {
      localsConvention: 'camelCase',
    },
  },
  server: {
    host: true,
    proxy: {
      '/xf/jointMes/api/websocket': {
        target: 'ws://47.113.200.153:32570',
        ws: true,
        rewriteWsOrigin: true,
      },
      '/xf/jointMes/api': {
        target: 'http://47.113.200.153:32570',
        changeOrigin: true,
      },
      '/api/download': {
        target: 'http://47.113.200.153:31301',
        changeOrigin: true,
      },
    },
  },
});
